#!/usr/bin/env python
# -*- coding: utf8 -*-
# title       :
# description :
# author      :'ShenMeng'

from PySide import QtGui, QtCore

from .pyuic.app_bar_widget import Ui_app_bar_widget
from .apps.screengrabber.screengrabber import ScreenGrabber
from functools import partial


class AppBarWidget(QtGui.QWidget):
    def __init__(self, parent=None):
        super(AppBarWidget, self).__init__(parent)
        self._ui = Ui_app_bar_widget()
        self._ui.setupUi(self)
        self.setStyleSheet('''
            *{background-color:rgba(0,0,0,0);}
            QToolButton:hover{background-color:rgba(0,0,0,10);}
            QFrame#frame{background-color:rgba(255,255,255,220)}
            ''')
        self._ui.cut_btn.mouseReleaseEvent = self.on_cut_btn_clicked
        self._ui.cmd_btn.hide()
        # self._ui.detail_btn.clicked.connect(self.show_menu)

        # self._menu = QtGui.QMenu()
    def show_menu(self):
        pos = QtCore.QPoint()
        pos.setX(0)
        pos.setY(-self._menu.sizeHint().height())
        self._menu.exec_(self._ui.detail_btn.mapToGlobal(pos))

    def _create_action(self, actions):
        for name in actions:
            action = QtGui.QAction(str(name), self)
            # action.triggered.connect(partial(self._set_version, str(name)))
            self._menu.addAction(action)

    def on_cmd_btn_clicked(self):
        pass

    def on_cut_btn_clicked(self, *args):
        # screen_grab = GifScreenGrabber()
        screen_grab = ScreenGrabber()
        screen_grab.show()




